package com.bb.flow.api.type;

/**
 * @author bigbeard on 2020-02-25
 * <p>
 * 表达式关系
 */
public enum ConditionLogicRelation {
    /**
     * 与
     */
    LOGIC_AND("与", 1),
    /**
     * 或
     */
    LOGIC_OR("或", 1),
    /**
     * 非
     */
    LOGIC_NOT("非", 2),
    /**
     * 包含
     */
    CONTENT("包含", 3);

    private final String text;
    private final int index;

    ConditionLogicRelation(String text, int index) {
        this.text = text;
        this.index = index;
    }

    /**
     * 根绝显示名称获取枚举
     *
     * @param t 描述
     * @return 枚举
     */
    public ConditionLogicRelation getByText(String t) {
        for (ConditionLogicRelation conditionLogicRelation : values()) {
            if (conditionLogicRelation.getText().equals(t)) {
                return conditionLogicRelation;
            }
        }
        return null;
    }

    /**
     * 根绝显示名称获取枚举
     *
     * @param i 值
     * @return 枚举
     */
    public ConditionLogicRelation getByIndex(int i) {
        for (ConditionLogicRelation conditionLogicRelation : values()) {
            if (conditionLogicRelation.getIndex() == i) {
                return conditionLogicRelation;
            }
        }
        return null;
    }

    public String getText() {
        return text;
    }

    public int getIndex() {
        return index;
    }
}
